Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: remove dependency on wallet backend packages #23019

Merged
merged 11 commits into from
Aug 25, 2021

Conversation

s1na
Copy link
Contributor

@s1na s1na commented Jun 8, 2021

After this PR those importing github.com/ethereum/go-ethereum/node won't need to pull in github.com/ethereum/go-ethereum/accounts/*.

API changes:

  • Node has an additional method KeyStoreDir
  • In NodeConfig, AccountConfig is replaced by KeyDirConfig (which doesn't return scrypt config)
  • Manager's Backends method now needs to acquire a read lock

@s1na s1na requested review from fjl and renaynay as code owners June 8, 2021 16:36
type NewBackendEvent struct {
backend Backend
wg *sync.WaitGroup
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type doesn't need to be exported. Also, it is not common to use WaitGroup for response signaling, it might be better to use a channel.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch re export. Also replaced the wg with a channel.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not tested it, but the code looks good to me

@s1na
Copy link
Contributor Author

s1na commented Jul 16, 2021

I rebased the branch and did some more testing. The account manager correctly detects the wallet and adds the accounts for clef and a hdwallet. I did send a tx via clef but getting "transaction type not supported" with a ledger which shouldn't be related to this PR. I didn't have a smart card to test with.

done := make(chan struct{}, len(backends))
for _, backend := range backends {
am.newBackends <- newBackendEvent{backend, done}
<-done
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also check if the quit is closed, otherwise this can be blocked forever.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quit is not closed ever though, it's a chan chan error. You'd need to add a term chan struct{} that gets closed if you want to check for it. Also, I think the block can only happen in am.newBackends <-, since once we read the event, we will surely respond.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select {
  case am.newBackends <- newBackendEvent{backend, done}:
  case <-am.term:
    return
}

node/node.go Outdated
@@ -42,7 +42,8 @@ type Node struct {
config *Config
accman *accounts.Manager
log log.Logger
ephemKeystore string // if non-empty, the key directory that will be removed by Stop
keydir string // key store directory
isKeyDirEphem bool // If true, key directory will be removed by Stop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keyDirTemp

kind := reflect.TypeOf(backend)
am.backends[kind] = append(am.backends[kind], backend)
am.lock.Unlock()
event.processed <- struct{}{}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do close(event.processed) if there's no actual error being returned.

func (am *Manager) AddBackends(backends ...Backend) {
done := make(chan struct{}, len(backends))
for _, backend := range backends {
am.newBackends <- newBackendEvent{backend, done}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done := make(chan struct)

@@ -93,6 +106,16 @@ func (am *Manager) Config() *Config {
return am.config
}

// AddBackends starts the tracking of additional backends for wallet updates.
// cmd/geth assumes once this func returns the backends have been already integrated.
func (am *Manager) AddBackends(backends ...Backend) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner to have just AddBackend. The constructor needs all the backends in one batch, but if we support adding them from the outside async, might as well add one-by-one.

@karalabe karalabe modified the milestones: 1.10.6, 1.10.7 Aug 3, 2021
@s1na s1na removed the status:triage label Aug 3, 2021
@s1na
Copy link
Contributor Author

s1na commented Aug 3, 2021

Updated with the suggested reviews

@fjl fjl changed the title accounts,node,cmd/geth: remove dependency on wallet backend packages from node node: remove dependency on wallet backend packages Aug 9, 2021
@karalabe karalabe modified the milestones: 1.10.7, 1.10.8 Aug 10, 2021
@fjl fjl modified the milestones: 1.10.8, 1.10.9 Aug 24, 2021
@fjl fjl self-assigned this Aug 24, 2021
@holiman holiman merged commit 108eec3 into ethereum:master Aug 25, 2021
@s1na s1na deleted the node-wallet-deps branch August 26, 2021 08:23
sidhujag pushed a commit to sidhujag/go-ethereum that referenced this pull request Aug 26, 2021
* accounts: new AddBackends method in manager

* node,cmd/geth: mv accman backend init to cmd/geth

* node,cmd/geth: mv scrypt config downstreawm from node

* accounts: use static buffer size for accman sub chan

minor fix

* accounts,cmd/geth: update accman backends through its event loop

* accounts,node: add comments

* accounts: un-export newBackendEvent

* accounts: use chan instead of wg in newBlockEvent

* node: rename isKeyDirEphem

* accounts,cmd: AddBackends->AddBackend

* accounts: fix potential blocking when adding backend
yongjun925 pushed a commit to DODOEX/go-ethereum that referenced this pull request Dec 3, 2022
* accounts: new AddBackends method in manager

* node,cmd/geth: mv accman backend init to cmd/geth

* node,cmd/geth: mv scrypt config downstreawm from node

* accounts: use static buffer size for accman sub chan

minor fix

* accounts,cmd/geth: update accman backends through its event loop

* accounts,node: add comments

* accounts: un-export newBackendEvent

* accounts: use chan instead of wg in newBlockEvent

* node: rename isKeyDirEphem

* accounts,cmd: AddBackends->AddBackend

* accounts: fix potential blocking when adding backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants